package com.cms.cmsbackend.service;

import com.cms.cmsbackend.mapper.CategoryMapper;
import com.cms.cmsbackend.pojo.Category;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.*;
import java.util.List;

@Service
public class CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;
    public  void save(Category category){
        categoryMapper.insert(category);
    }
    public void remove(int id){

        categoryMapper.deleteByPrimaryKey(id);
    }
    public  void update(Category category){

        categoryMapper.updateByPrimaryKeySelective(category);
    }
    public PageInfo selectByPage(int page,int size){
        PageHelper.startPage(page,size);
        List<Category> categories=categoryMapper.selectAll();
        return new PageInfo(categories);
    }
    public Category select(int id){
        return categoryMapper.selectByPrimaryKey(id);
    }
}
